/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package poker.neuralnetwork;

/**
 * A connection between two perceptrons. The connection contains both perceptrons
 * plus an edge weight.
 *
 * 
 * @author Benjamin L. Brodie <blbrodie@gmail.com>
 */
public class Edge {
    private Double weight;
    private Perceptron incoming;
    //private Perceptron p2; //uncomment if we need to know forward direction


    /**
     *
     * @param incoming the incoming perceptron
     * @param outgoing the outgoing perceptron
     * @param weight the edge weight
     *
     * Incoming perceptron is the perceptron that the signal is coming from.
     * Outgoing perceptron is the perceptron that the signal is traveling to.
     *
     * 
     *
     *
     *
     */
    public Edge(Perceptron incoming) {
        this.incoming = incoming;
        //this.p2 = outgoing; //do we even need this??
        this.weight = null; //null is default
    }

    /**
     * Updates the weight by the given amount. Note that it adds this value, not
     * replaces it!
     *
     * @param addValue the value to be added.
     */
    public void addToWeight(double addValue){
        if (weight == null){
            throw new IllegalArgumentException("no weight value has been set!");
        }
        weight += addValue;
    }

    /**
     * Sets a weight value. Note that this sets the weight to the given amount!
     * use addToWeight(value) to add (or subtract) a value.
     *
     * @param setValue
     */
    public void setWeight(double setValue){
        weight = setValue;
    }
    
    /**
     * Method returns the incoming perceptron's output multiplied by the edge weight.
     * 
     * i.e.,
     * 
     * input = previous output * weight
     *
     *
     * 
     * 
     * @return the weighted value of the output of the incoming perceptron.
     */
    public double input(){
        return incoming.output() * weight;
    }

    /**
     * Returns the weight associated with the edge.
     *
     * @return the edge weight
     */
    public double getWeight(){
        return weight;
    }

    /**
     * Returns the incoming perceptron.
     *
     *
     * @return the incoming perceptron.
     *
     * NOTE: Perceptrons that extend AbstractPerceptron should be immutable. This
     *       method does not return a copy. Used for referencing the same
     *       perceptron. Changes to immutable perceptrons (eg, Inputs) will be
     *       reflected in the network! This is intended in the case of input
     *       perceptrons.
     */
    public Perceptron getIncoming(){
        return incoming;
    }

    @Override
    public String toString(){
        return "w = " + weight + " incoming type: " + incoming;
    }


}
